#include <stdio.h>
#include <string.h>
#include <malloc.h>

struct Student {
    int age;

    char *name;

    char *phone;
};

// typedef 可以给数据结构取别名
typedef struct Student Student;

int main() {
    // student_01 在定义的时候已经分配了内存空间, 并且 student_01 是用 . 来访问内部变量的值
    Student student_01;
    printf("%lu\n", sizeof(student_01)); // 24

    student_01.age = 19;
    memcpy(student_01.name, "Blue123242124124", sizeof(char) * strlen("Blue123242124124"));
    memcpy(student_01.phone, "10086", sizeof(char) * strlen("10086"));
    printf("age = %d name = %s phone = %s\n", student_01.age, student_01.name, student_01.phone);

    // student_02 在定义时没有分配内存空间, 并且 student_02 是用 -> 来访问内部变量的值
    Student *student_02 = (Student *) malloc(sizeof(Student));
    printf("%lu\n", sizeof(student_02)); // 8

    student_02->age = 22;
    student_02->name = malloc(sizeof(char) * 1024);
    memcpy(student_02->name, "Yui", sizeof(char) * strlen("Yui"));
    student_02->phone = malloc(sizeof(char) * 1024);
    memcpy(student_02->phone, "10001", sizeof(char) * strlen("10001"));

    printf("age = %d name = %s phone = %s\n", student_02->age, student_02->name, student_02->phone);

    return 0;
}